#!/usr/bin/env python

import wx

class Messages(object):
    '''Messages class
    
    @author Julot <andy.julot@gmail.com>
    @since Friday, February 24, 2012. 09:54 AM'''
    
    def __init__(self, view, presenter):
        self.view = view
        self.presenter = presenter
        self.bind()
        
    def bind(self):
        view = self.view
        
        menu = view.MenuBar
        
        view.Bind(wx.EVT_MENU, self.archive, menu.message.archive)
        view.Bind(wx.EVT_MENU, self.delete, menu.message.delete)
        view.Bind(wx.EVT_MENU, self.recover, menu.message.recover)
        view.Bind(wx.EVT_MENU, self.export, menu.message.export)
        
        tool = view.messages.toolBar
        
        view.Bind(wx.EVT_MENU, self.archive, tool.archive.tool)
        view.Bind(wx.EVT_MENU, self.delete, tool.delete.tool)
        view.Bind(wx.EVT_MENU, self.recover, tool.recover.tool)
        view.Bind(wx.EVT_MENU, self.export, tool.export.tool)
        
        view.Bind(wx.EVT_LISTBOX, self.filter, view.messages.labels)
        view.Bind(wx.EVT_LIST_ITEM_SELECTED, self.show,
                  view.messages.messages)
        
    def filter(self, event):
        self.presenter.messages.filter(event.String)
    
    def archive(self, event):
        self.presenter.messages.archive()
    
    def delete(self, event):
        self.presenter.messages.delete()
    
    def recover(self, event):
        self.presenter.messages.recover()
    
    def show(self, event):
        event.Skip()
        self.presenter.messages.show(event.Index, event.Data)

    def export(self, event):
        path = self.presenter.messages.confirmExport()
        if path: self.presenter.messages.export(path)
